# 默认值为可变对象 设置为None
# def f(a, l=[]):
#     l.append(a)
#     return l
# def f(a, l=None):
#     if l is None:
#         l = []
#     l.append(a)
#     return l
#
# print(f(1))
# print(f(2))
# print(f(3))

# TODO 可变参数
def variable_fun(kind, *arguments, **keywords):
    print("friend : ", kind, ";")
    print("-" * 40)
    for arg in arguments:
        print(arg)
    print("-" * 40)
    for kw in keywords:
        print(kw, ":", keywords[kw])

# variable_fun("xiaoming",
#              "hello xiaoming", "nice to meet you!",
#             mother="xiaoma",
#             father="xiaoba",
#             son="see you")
list01 = ["hello xiaoming", "nice to meet you!"]
dict01 = {'mother': 'xiaoma', 'father': 'xiaoba', 'son': 'see you'}
# 解包操作
# variable_fun("xiaoming", *list01, **dict01)

# TODO 关键字参数
# 借用官网例子
def key_fun(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
    print("-- This key_fun wouldn't", action, end=' ')
    print("if you put", voltage, "volts through it.")
    print("-- Lovely plumage, the", type)
    print("-- It's", state, "!")

# 函数调用
# key_fun(1000)                                          # 1 positional argument
# key_fun(voltage=1000)                                  # 1 keyword argument
# key_fun(voltage=1000000, action='VOOOOOM')             # 2 keyword arguments
# key_fun(action='VOOOOOM', voltage=1000000)             # 2 keyword arguments
# key_fun('a million', 'bereft of life', 'jump')         # 3 positional arguments
# key_fun('a thousand', state='pushing up the daisies')  # 1 positional, 1 keyword

# 注意不可以重复传值,否则会报如下错误:
key_fun(100, voltage=1000) 
